﻿<Window x:Class="JBrute.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:local="clr-namespace:JBrute" 
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase" 
    Title="JBrute 4 Dev" Height="600" Width="800" ContentRendered="Window_ContentRendered" 
    FocusManager.FocusedElement="{Binding ElementName=FindMeText}" >
   <Window.Resources>
      <DataTemplate x:Key="HeaderTemplateArrowUp">
         <DockPanel>
            <TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
            <Path x:Name="arrow"
           StrokeThickness = "1"                                     
           Fill            = "gray"
           Data            = "M 5,10 L 15,10 L 10,5 L 5,10"/>
         </DockPanel>
      </DataTemplate>
      <DataTemplate x:Key="HeaderTemplateArrowDown">
         <DockPanel>
            <TextBlock HorizontalAlignment="Center" Text="{Binding }"/>
            <Path x:Name="arrow"
              StrokeThickness = "1"                                  
              Fill            = "gray"
              Data            = "M 5,5 L 10,10 L 15,5 L 5,5"/>
         </DockPanel>
      </DataTemplate>
      <local:ArrayListConverter x:Key="ArrayListConverter" />
      <local:DetailsConverter x:Key="DetailsConverter" />
      <local:WidthConverter x:Key="WidthConverter" />
      <local:IMEModeConverter x:Key="IMEModeConverter" />
      <local:CurrentHistoryIndexConverter x:Key="CurrentHistoryIndexConverter" />
   </Window.Resources>
   <Grid>
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto"/>
         <RowDefinition Height="*"/>
         <RowDefinition Height="Auto"/>
      </Grid.RowDefinitions>
      <ToolBar Name="toolBar" KeyboardNavigation.TabNavigation="Continue" Focusable="True">
         <Button Name="btnBack" ToolTip="Back" Click="HistoryNavigate" IsEnabled="{Binding Path=CurrentHistoryIndex, Converter={StaticResource CurrentHistoryIndexConverter}, ConverterParameter=back}" IsTabStop="False">
            <Image Source="/JBrute;component/Resources/BackArrow.png" Height="48"/>
         </Button>
         <Button Name="btnFwd" ToolTip="Foreward" Click="HistoryNavigate" IsEnabled="{Binding Path=CurrentHistoryIndex, Converter={StaticResource CurrentHistoryIndexConverter}, ConverterParameter=fwd}" IsTabStop="False">
            <Image Source="/JBrute;component/Resources/ForewardArrow.png" Height="48"/>
         </Button>
         <GroupBox Margin="3" Header="{Binding Path=IMEMode, Converter={StaticResource IMEModeConverter}}"
            MouseUp="ChangeIMEMode">
            <GroupBox.ToolTip>
               <TextBlock Width="480" TextWrapping="Wrap">
                    Enter the search term(s) here (English or Japanese).  Examples:<LineBreak/>
                     - book<LineBreak/>
                     - 気 / 気% <LineBreak/>
                     - 気_ or _気<LineBreak/>
                     - "may I help you"<LineBreak/>
                     - "to run" president (multiple terms must all be present)<LineBreak/>
                  <LineBreak/>
                  Alt-D: jumps back (sets focus) to this text box.<LineBreak/>
                  Alt-I: toggles the IME mode (to write Hiragana, Katakana, Kanji or English)
               </TextBlock>
            </GroupBox.ToolTip>
            <TextBox Name="FindMeText" FontSize="22" FontStyle="Italic" Width="300" TextChanged="FindMeText_Changed" VerticalContentAlignment="Center" GotKeyboardFocus="TXTGotFocus" MaxHeight="40"></TextBox>
         </GroupBox>
         <StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="10, 0, 10, 0">
            <CheckBox FontSize="16" IsChecked="{Binding Path=ClipBoardMonitor}" ToolTip="Automatically look up Japanese text you copy in another application" Checked="ToggleClipBoard" Unchecked="ToggleClipBoard" HorizontalAlignment="Left" IsTabStop="False">_Clipboard to  vocab. list</CheckBox>
            <CheckBox FontSize="16" IsChecked="{Binding Path=PinToTop}" ToolTip="Keep JBrute in front so you can always see it" Checked="TogglePinToTop" Unchecked="TogglePinToTop" HorizontalAlignment="Left" IsTabStop="False">_Topmost window</CheckBox>
         </StackPanel>
         <!-- The Vista Style is applied using a ComponentResourceKey   -->
         <local:SplitButton HorizontalAlignment="Right" IsTabStop="False" 
								Style="{DynamicResource {x:Static local:SplitButtonResources.VistaSplitButtonStyleKey}}"
								Mode="Dropdown" 
								>
            <local:SplitButton.Content>
               <StackPanel Orientation="Horizontal">
                  <Image Source="/JBrute;component/Resources/HelpMark.png" Height="48"/>
               </StackPanel>
            </local:SplitButton.Content>
            <MenuItem Header="Help" Click="HelpClick"/>
            <MenuItem Header="About JBrute" Click="AboutClick"/>
         </local:SplitButton>
      </ToolBar>
      <Grid Grid.Row="1" >
         <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
         </Grid.ColumnDefinitions>
         <ListView Name="lvResults" ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler" GotFocus="LVGotFocus" FontSize="20" SelectionMode="Single">
            <ListView.ContextMenu>
               <ContextMenu>
                  <MenuItem Command="Copy"  Header="Copy All"/>
               </ContextMenu>
            </ListView.ContextMenu>
            <ListView.View>
               <GridView ColumnHeaderToolTip="Search Results" >
                  <GridViewColumn Header="Kanji" Width="100">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock ToolTip="{Binding Data.kanji}" VerticalAlignment="Center" Text="{Binding Data.kanji, Converter={StaticResource ArrayListConverter}}" />
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="Kana" Width="100">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock ToolTip="{Binding Data.kana}" VerticalAlignment="Center" Text="{Binding Data.kana, Converter={StaticResource ArrayListConverter}}" />
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
                  <GridViewColumn Header="English" Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListView}},Converter={StaticResource WidthConverter}}">
                     <GridViewColumn.CellTemplate>
                        <DataTemplate>
                           <TextBlock ToolTip="{Binding Data.english}" VerticalAlignment="Center" Text="{Binding Data.english}" />
                        </DataTemplate>
                     </GridViewColumn.CellTemplate>
                  </GridViewColumn>
               </GridView>
            </ListView.View>
         </ListView>
         <WindowsFormsHost Tag="{Binding Path=Data, Converter={StaticResource DetailsConverter}}" Grid.Column="1" >
            <wf:WebBrowser x:Name="details" DocumentCompleted="details_LoadCompleted" />
         </WindowsFormsHost>
         <GridSplitter Width="5"  />
      </Grid>
      <StatusBar Name="statusBar" Grid.Row="2">
         <StatusBar.ItemsPanel>
            <ItemsPanelTemplate>
               <Grid>
                  <Grid.RowDefinitions>
                     <RowDefinition Height="*"/>
                  </Grid.RowDefinitions>
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="150"/>
                     <ColumnDefinition Width="150"/>
                     <ColumnDefinition Width="150"/>
                     <ColumnDefinition Width="50"/>
                     <ColumnDefinition Width="*"/>
                  </Grid.ColumnDefinitions>
               </Grid>
            </ItemsPanelTemplate>
         </StatusBar.ItemsPanel>
         <StatusBarItem>
            <TextBlock ToolTip="matching dictionary entries"  Text="{Binding NumResultsEntries}"></TextBlock>
         </StatusBarItem>
         <StatusBarItem Grid.Column="1">
            <TextBlock ToolTip="matching example sentences"  Text="{Binding NumResultsExamples}"></TextBlock>
         </StatusBarItem>
         <StatusBarItem Grid.Column="2">
            <TextBlock ToolTip="Time to query (but not fetch) both the entries and examples"  Text="{Binding SearchTime}"></TextBlock>
         </StatusBarItem>
         <StatusBarItem Grid.Column="3">
            <TextBlock TextAlignment="Right" ToolTip="Memory usage"  Text="{Binding MemUsage}"></TextBlock>
         </StatusBarItem>
         <StatusBarItem Grid.Column="4">
             <TextBlock TextAlignment="Right" ToolTip="Debug String"  Text="{Binding DebugString}"></TextBlock>
         </StatusBarItem>

        </StatusBar>
   </Grid>
</Window>
